package db4oToOracle.obj1test;


import com.googlecode.datawander.connectors.Db4oUtil;
import com.googlecode.datawander.connectors.OracleConnector;
import java.sql.SQLException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MarcinStachniuk
 */
public abstract class SuperSuperTask {

    private String superSuperDescription = "sup sup desc";

    public static void saveAllRecords(SuperSuperTask [] ssTasks) throws Exception {
        if(ssTasks != null) {
            java.sql.Connection conn = OracleConnector.getConnection();
            for(SuperSuperTask o : ssTasks) {
                o.saveRecord(conn);
            }
        }
    }

    private void saveRecord(java.sql.Connection conn) throws SQLException {
        String sql = "insert into \"SuperSuperTask\" (\"GENERATED_ID\", \"superSuperDescription\") " +
                "values (?,?)";
        java.sql.PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setLong(1, getIdFromDb4o());
        stmt.setString(2, superSuperDescription);

        stmt.executeUpdate();
        System.out.println("Zapisano Task id: "+getIdFromDb4o() + " name: " +
                superSuperDescription + " id AppUser ");
    }

    public String getSuperSuperDescription() {
        return superSuperDescription;
    }

    public void setSuperSuperDescription(String superSuperDescription) {
        this.superSuperDescription = superSuperDescription;
    }

    /**
     * Pobiera id z db4o. Zakładam ze wynik bedzie inny niz zero, w przeciwnym
     * wypadku bedzie to obiekt ktorego nie bylo w db4o
     * @return
     */
    public long getIdFromDb4o() {
        com.db4o.ObjectContainer db = Db4oUtil.getObjectContainer();
        long id = db.ext().getID(this);
        return id;
    }
}
